home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / lernen / ddd_plot / pic2dif.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  2.6 KB  |  128 lines

  1. /* Konvertiert Bilddaten in DIF-File, von Jörg Ramb */
  2.  
  3. #include    <stdio.h>
  4. #include    <stdlib.h>
  5. #include    <aes.h>
  6. #include    <vdi.h>
  7. #include    <tos.h>
  8. #include    <string.h>
  9. #include    <homemade.h>
  10.  
  11. #define    hide_mouse()    v_hide_c(vdihandle)
  12. #define    show_mouse()    v_show_c(vdihandle,1)
  13.  
  14. int vdihandle;
  15. int    x,y,b,h;
  16.  
  17. char    save[32000L];
  18.  
  19. void read_pic(void)
  20. {
  21.     FILE *fil;
  22.     static char name[16]="",pfad[64]="X:\*.PIC",fn[80]="";
  23.     long xb;
  24.  
  25.     pfad[0]=Dgetdrv()+'A';
  26.     xb=get_in_file(pfad,name,fn);
  27.     if(xb)    return;
  28.  
  29.     hide_mouse();
  30.     fil=fopen(fn,"rb");
  31.     if(!fil)    return;
  32.     fread(Physbase(),32000L,1L,fil);
  33.     memcpy(save,Physbase(),32000L);
  34.     fclose(fil);
  35.     show_mouse();
  36. }
  37.  
  38. void drawaxis(int x,int y)
  39. {
  40.     int pxyarray[4];
  41.     pxyarray[0]=0;        pxyarray[1]=y;
  42.     pxyarray[2]=639;    pxyarray[3]=y;
  43.     vs_clip(vdihandle,0,pxyarray);
  44.     vswr_mode(vdihandle,MD_XOR);
  45.     v_pline(vdihandle,2,pxyarray);
  46.     pxyarray[0]=x;        pxyarray[1]=0;
  47.     pxyarray[2]=x;        pxyarray[3]=399;
  48.     v_pline(vdihandle,2,pxyarray);
  49. }
  50.  
  51. void get_range(void)
  52. {
  53.     int    ms,mx,my,mx2,my2;
  54.     hide_mouse();
  55.     memcpy(Physbase(),save,32000L);
  56.     do    vq_mouse(vdihandle,&ms,&mx,&my);    while(ms!=0);
  57.     drawaxis(mx,my);
  58.     do    {
  59.         drawaxis(mx,my);
  60.         vq_mouse(vdihandle,&ms,&mx,&my);
  61.         drawaxis(mx,my);
  62.     }    while(ms==0);
  63.     do    vq_mouse(vdihandle,&ms,&mx2,&my2);    while(ms!=0);
  64.     drawaxis(mx2,my2);
  65.     do    {
  66.         drawaxis(mx2,my2);
  67.         vq_mouse(vdihandle,&ms,&mx2,&my2);
  68.         if((mx2-mx)>100)    mx2=mx+100;
  69.         if((my2-my)>100)    my2=my+100;
  70.         drawaxis(mx2,my2);
  71.     }    while(ms==0 || mx2<=mx || my2<=my);
  72.     drawaxis(mx2,my2);
  73.     show_mouse();
  74.     x=mx;    y=my;    b=mx2-mx;    h=my2-my;
  75. }
  76.  
  77. void write_dif(void)
  78. {
  79.     FILE *fil;
  80.     static char name[16]="",pfad[64]="X:\*.DIF",fn[80]="";
  81.     int xx,yy;
  82.  
  83.     pfad[0]=Dgetdrv()+'A';
  84.  
  85.     xx=get_in_file(pfad,name,fn);
  86.     if(xx)    return;
  87.  
  88.     fil=fopen(fn,"w");
  89.     if(!fil)    return;
  90.  
  91.     hide_mouse();
  92.     memcpy(Physbase(),save,32000L);
  93.     fprintf(fil,"TABLE\n0,1\n\"PIC2DIF\"\n"
  94.         "TUPLES\n0,%d\n\"\"\nVECTORS\n0,%d\n"
  95.         "\"\"\nDATA\n0,0\n\"\"\n-1,0\n",
  96.         h,b);
  97.     for(yy=h-1;yy>=0;yy--)    {
  98.         fprintf(fil,"BOT\n");
  99.         for(xx=0;xx<b;xx++)    {
  100.             int pel,index;
  101.             v_get_pixel(vdihandle,x+xx,y+yy,&pel,&index );
  102.             fprintf(fil,"0,%d\nV\n",pel);
  103.         }
  104.         fprintf(fil,"-1,0\n");
  105.     }
  106.     fprintf(fil,"EOD\n");
  107.     fclose(fil);
  108.     show_mouse();
  109. }
  110.  
  111. void main(void)
  112. {
  113.     if(Getrez()!=2)    return;
  114.     if(appl_init()>=0)    {
  115.         int        dummy;
  116.         vdihandle=graf_handle(&dummy,&dummy,&dummy,&dummy);
  117.  
  118.         printf("\033E"
  119. "DIF-Generator von Jörg Ramb - Bestandteil von DDD-Plot - Public Domain!\n\n"
  120. "Wandelt einen Grafikausschnitt (Screen-Format) in ein DIF-File um:");
  121.  
  122.         read_pic();
  123.         get_range();
  124.         write_dif();
  125.         appl_exit();
  126.     }
  127. }
  128.